package com.zhinong.controller.admin;

import com.zhinong.dto.OrderPageQueryDTO;
import com.zhinong.entity.Order;
import com.zhinong.result.PageResult;
import com.zhinong.result.Result;
import com.zhinong.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "订单相关接口")
@Slf4j
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @GetMapping("/page")
    @ApiOperation("订单分页查询")
    public Result<PageResult> pageQuery(OrderPageQueryDTO orderPageQueryDTO){
        log.info("订单分页查询,参数为:{}",orderPageQueryDTO);
        PageResult pageResult= orderService.pageQuery(orderPageQueryDTO);
        return Result.success(pageResult);
    }


    @DeleteMapping("/{id}")
    @ApiOperation("删除订单")
    public Result deleteById(@PathVariable Long id){
        log.info("删除订单：{}",id);
        orderService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增订单")
    public Result insert(@RequestBody Order order) throws Exception {
        log.info("新增订单：{}",order);
        orderService.insert(order);
        return Result.success();
    }

    @PutMapping("/{id}")
    public Result update(@RequestBody Order order){
        log.info("修改订单：{}",order);
        orderService.update(order);
        return Result.success();
    }
}
